package com.atguigu.gmallsuger.mapper;

import com.atguigu.gmallsuger.bean.C3Stats;
import com.atguigu.gmallsuger.bean.SpuStats;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/10/14 9:21
 */
public interface ProductMapper {
    
    @Select("SELECT sum(order_amount)\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}")
    BigDecimal gmv(@Param("date") int date);
    
    @Select("SELECT\n" +
        "    tm_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n" +
        "GROUP BY tm_name\n" +
        "ORDER BY order_amount DESC\n" +
        "LIMIT 5\n")
    List<Map<String, Object>> getGMVByTmName(@Param("date") int date);
    
    @Select("SELECT\n" +
        "    category3_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n" +
        "GROUP BY category3_name\n" +
        "ORDER BY order_amount DESC\n" +
        "LIMIT 5\n")
    List<C3Stats> getGMVByC3Name(@Param("date") int date);
    
    @Select("SELECT\n" +
        "    spu_name,\n" +
        "    sum(order_amount) AS order_amount\n" +
        "FROM product_stats_2021\n" +
        "WHERE toYYYYMMDD(stt) = #{date}\n" +
        "GROUP BY spu_name\n")
    List<SpuStats> getGMVBySpuName(@Param("date") int date);
    
    
    
}
